Skip to content

fix: skip double conversion when time values are already in milliseconds - #47

Closed
Sufiyan-MSA wants to merge 1 commit into
OSIPI:mainfrom
Sufiyan-MSA:fix/issue-14-double-unit-conversion-time-ms
Closed

Sufiyan-MSA wants to merge 1 commit into
OSIPI:mainfrom
Sufiyan-MSA:fix/issue-14-double-unit-conversion-time-ms

Conversation

@Sufiyan-MSA

Copy link
Copy Markdown

Fixes #14

What this fixes

Stops time fields (e.g. PostLabelingDelay, EchoTime, RepetitionTimePreparation) that are already in milliseconds in the input from being multiplied by 1000 again, which was producing wrong values (e.g. 1800 → 1,800,000).

What I changed

  • package/src/pyaslreport/utils/unit_conversion_utils.py: In convert_to_milliseconds, added a heuristic so that if a scalar time value is greater than 10, or any element in a list is greater than 10, the value(s) are treated as already in milliseconds and conversion is skipped. Typical ASL times in seconds (EchoTime ~0.01–0.03 s, PLD ~1–3 s, RepetitionTime ~3–6 s) are all below 10, so this threshold avoids double conversion while keeping seconds→ms conversion for values in seconds.

How I tested it

Ran the four scenarios from the issue: (1) scalar seconds → ms (e.g. 1.8 → 1800), (2) scalar already ms unchanged (e.g. 1800 → 1800, 15 → 15, 4000.0 → 4000.0), (3) list already ms unchanged ([1800, 2000, 2200]), (4) list seconds → ms ([1.8, 2.0, 2.2] → [1800, 2000, 2200]). Confirmed no new linter issues on the modified file.

Notes

Fix is implemented only in UnitConverterUtils.convert_to_milliseconds; both the session normalization path and the M0 time conversion path in processor.py use this method, so both are fixed without further changes.

@Devguru-codes

This comment was marked as spam.

@Sufiyan-MSA Sufiyan-MSA closed this by deleting the head repository Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double unit conversion corrupts time data when values are already in milliseconds (Help needed)

2 participants